<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Datei: message.class.php
 *
 * At file and database operations message these appear (can) 
 * collect and distribute the different. 
 * if empty = No message availible
 *
 * @author Norbert Gebert
 * @copyright Norbert Gebert 25.09.2011
 * @license GPL3
 *
 * @version 0.5b
 * @package Admin
 * @subpackage global
 */
class message
{

	// @var $text String Text from the last called message
	static $text = '';

	/**
	 * Initializes the system-variable if still not available. 
	 */
	function __construct()
	{
		if (!isset($_SESSION['_ifErrorMessagex']))
		// @var $_ifErrorMessage Boolean True if a message occur
			$_SESSION['_ifErrorMessagex'] = false;

		if (!isset($_SESSION['_ifNoteMessagex']))
		// @var $_ifNoteMessage Boolean True if a message occur
			$_SESSION['_ifNoteMessagex'] = false;

		if (!isset($_SESSION['_ifWarningMessagex']))
		// @var $_ifWarningMessage Boolean True if a message occur
			$_SESSION['_ifWarningMessagex'] = false;

		if (!isset($_SESSION['_errorTextx']))
		// @var $_errorText String Full Errormessage 
			$_SESSION['_errorTextx'] = '';

		if (!isset($_SESSION['_noteTextx']))
		// @var $_noteText String Full Errormessage 
			$_SESSION['_noteTextx'] = '';

		if (!isset($_SESSION['_warningTextx']))
		// @var $_warningText String Full Errormessage 
			$_SESSION['_warningTextx'] = false;
	}

	/**
	 * setting the error-message
	 * @param string $row Text of one row from the message 
	 * @param option $first Set the row on top-position if it true
	 */
	public static function setErrorRow($row, $first = false)
	{
		if ($first)
		{
			$_SESSION['_errorTextx'] = '<b>' . $row . '</b><br>' . $_SESSION['_errorTextx'];
		}
		else
		{
			$_SESSION['_errorTextx'] .= '- ' . $row . '<br>';
		}
		$_SESSION['_ifErrorMessagex'] = true;
	}

	public static function getErrorText()
	{
		self::$text = $_SESSION['_errorTextx'];
		$_SESSION['_errorTextx'] = '';
		$_SESSION['_ifErrorMessagex'] = false;
		return self::$text;
	}

	public static function setNoteRow($row, $first = false)
	{
		if ($first)
		{
			$_SESSION['_noteTextx'] = '<b>' . $row . '</b><br>' . $_SESSION['_noteTextx'];
		}
		else
		{
			$_SESSION['_noteTextx'] .= '- ' . $row . '<br>';
		}
		$_SESSION['_ifNoteMessagex'] = true;
	}

	public static function getNoteText()
	{
		self::$text = $_SESSION['_noteTextx'];
		$_SESSION['_noteTextx'] = '';
		$_SESSION['_ifNoteMessagex'] = false;
		return self::$text;
	}

	public static function setWarningRow($row, $first = false)
	{
		if ($first)
		{
			$_SESSION['_warningTextx'] = '<b>' . $row . '</b><br>' . $_SESSION['_warningTextx'];
		}
		else
		{
			$_SESSION['_warningTextx'] .= '- ' . $row . '<br>';
		}
		$_SESSION['_ifWarningMessagex'] = true;
	}

	public static function getWarningText()
	{
		self::$text = $_SESSION['_warningTextx'];
		$_SESSION['_warningTextx'] = '';
		$_SESSION['ifWarningMessagex'] = false;
		return self::$text;
	}

	public static function ifErrorMessage()
	{
		if (isset($_SESSION['_ifErrorMessagex']))
		{
			return $_SESSION['_ifErrorMessagex'];
		}
	}

	public static function ifNoteMessage()
	{
		if (isset($_SESSION['_ifNoteMessagex']))
		{
			return $_SESSION['_ifNoteMessagex'];
		}
	}

	public static function ifWarningMessage()
	{
		if (isset($_SESSION['_ifWarningMessagex']))
		{
			return $_SESSION['_ifWarningMessagex'];
		}
	}

}

?>